package com.lanchetech.admin.controller;

import com.lanchetech.admin.aop.OperatorLog;
import com.lanchetech.admin.service.FundService;
import com.lanchetech.bean.request.CommissionRecordPageReq;
import com.lanchetech.bean.request.FreezeAmountReq;
import com.lanchetech.bean.request.PageReq;
import com.lanchetech.bean.response.BasePageResp;
import com.lanchetech.bean.response.BaseResp;
import com.lanchetech.bean.response.ResultData;
import com.lanchetech.bean.vo.*;
import com.lanchetech.entity.FreezeAmount;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

@Api(value = "资金管理接口", tags = "资金管理接口")
@RequestMapping("/api/fund")
@RestController
public class FundController {

    @Autowired
    FundService fundService;

    @ApiOperation(value = "获取资金余额流水分页", notes = "筛选条件 userId, status->tradeType, search->remark, type, startTime, endTime")
    @PreAuthorize("hasAuthority('fund.balance-index')")
    @PostMapping("/getBalanceFlowPage")
    public ResultData<BasePageResp<BalanceFlowVO>> getBalanceFlowPage(@RequestBody PageReq req) {
        return fundService.getBalanceFlowPage(req);
    }

    @ApiOperation(value = "获取积分流水分页", notes = "筛选条件 userId, status->tradeType, search->remark, type, startTime, endTime")
    @PreAuthorize("hasAuthority('fund.coin-index')")
    @PostMapping("/getCoinFlowPage")
    public ResultData<BasePageResp<CoinFlowVO>> getCoinFlowPage(@RequestBody PageReq req) {
        return fundService.getCoinFlowPage(req);
    }

    @ApiOperation("获取总佣金记录分页")
    @PreAuthorize("hasAuthority('fund.index')")
    @PostMapping("/getCommissionRecordPage")
    public ResultData<BasePageResp<CommissionRecordVO>> getCommissionRecordPage(@RequestBody CommissionRecordPageReq req) {
        return fundService.getCommissionRecordPage(req);
    }

    @ApiOperation("获取总佣金统计金额之和")
    @PreAuthorize("hasAuthority('fund.index')")
    @PostMapping("/getCommissionSum")
    public ResultData<BigDecimal> getCommissionSum(@RequestBody PageReq req) {
        return fundService.getCommissionSum(req);
    }

//    @OperatorLog("直接向用户发放佣金")
//    @ApiOperation("直接向用户发放佣金")
//    @PreAuthorize("hasAuthority('user.detail.commission.auth')")
//    @GetMapping("/issueCommissionDirect")
//    public BaseResp issueCommissionDirect(@RequestParam("amount") BigDecimal amount, @RequestParam("userId") Long userId) {
//        return fundService.issueCommissionDirect(amount, userId);
//    }


    @OperatorLog("直接向用户发放积分")
    @ApiOperation("直接向用户发放积分")
    @PreAuthorize("hasAuthority('user.detail.coin.auth')")
    @GetMapping("/issueCoinDirect")
    public BaseResp issueCoinDirect(@RequestParam("coin") BigDecimal coin, @RequestParam("userId") Long userId) {
        return fundService.issueCoinDirect(coin, userId);
    }

    @ApiOperation("获取所有商家提现申请分页")
    @PostMapping("/getAllTenantWithdrawPage")
    public ResultData<BasePageResp<TenantWithdrawVO>> getAllTenantWithdrawPage(@RequestBody PageReq req) {
        return fundService.getAllTenantWithdrawPage(req);
    }

    @OperatorLog(value = "审核商家提现申请")
    @ApiOperation("审核商家提现申请")
    @PostMapping("/auditTenantWithdraw")
    public BaseResp auditTenantWithdraw(@RequestBody TenantWithdrawVO req) {
        return fundService.auditTenantWithdraw(req);
    }

    @ApiOperation("获取商家余额流水")
    @PostMapping("/getTenantFlowPage")
    public ResultData<BasePageResp<TenantFlowVO>>  getTenantFlowPage(@RequestBody PageReq req) {
        return fundService.getTenantFlowPage(req);
    }

    @ApiOperation("获取商家冻结金额分页")
    @PostMapping("/getFreezeAmountPage")
    public ResultData<BasePageResp<FreezeAmountVO>>  getFreezeAmountPage(@RequestBody FreezeAmountReq req) {
        return fundService.getFreezeAmountPage(req);
    }
}
